/*
 * Created on Feb 19, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package ModuleBuilder.model;

import java.util.*;
import java.io.*;

import ModuleBuilder.UI.tree.*;
import littlecyberwar.ui.*;
/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 * 
 * This class handles all the data for a particular UnitTemplate, and is the 
 * Model for the UnitTemplateEditor View
 */
public class UnitModel extends GameModel implements Serializable {

	private ArrayList stands;	// holds all the attributes (use ArrayList because we want to maintain order)
	private boolean isCommand; 	// this is set if this node (and all decendents) can be operating as a separate command
	private UnitProfileModel profileModel;	// point to the applicable profile/ If this is NULL then ea. stand will have its own profile
	private HashMap rangeValue;	// name value pair where any variable Range of value is stored
	private Element element;
	private Integer id;		// unique unit id used to populate the unit dictionary
	
	private static int idSeed = 1;
	private ImageElement sideImage;
		
	/**
	 * @param nameIn
	 * @param editorNameIn
	 * @param isMainEditorIn
	 * @param edIn
	 */

	/**
	 * 
	 */
//	public UnitTypeGameTreeNode() {
//		super(null, null, false, null);
//		attributes = new ArrayList();
//	}
//	
	public UnitModel(String nameIn, String editorIn, boolean isEditorIn, iEditorPanel edIn) {
		super( nameIn, editorIn, isEditorIn, edIn );
		stands = new ArrayList(1);
	}
		
	public void addStand( Stand valIn ) {
		stands.add(valIn);
	}
	
	public void removeAllStands() {
		stands.clear();	
	}	
	/**
	 * @return
	 */
	public ArrayList getStands() {
		return stands;
	}

	/**
	 * @return
	 */
	public boolean isCommand() {
		return isCommand;
	}

	/**
	 * @param b
	 */
	public void setCommand(boolean b) {
		isCommand = b;
	}

	/**
	 * @return
	 */
	public UnitProfileModel getProfileModel() {
		return profileModel;
	}

	/**
	 * @param node
	 */
	public void setProfileModel(UnitProfileModel node) {
		profileModel = node;
	}

	/**
	 * @return
	 */
	public HashMap getRangeValue() {
		return rangeValue;
	}
	
	public void addHashValue(String name, Object val) {
		if ( rangeValue == null ) {
			rangeValue = new HashMap();
		}
		rangeValue.put(name, val);
		return;
	}
	
	public Object getHashValue(String name) {
		Object res = null;
		if ( rangeValue != null ){
			res = rangeValue.get(name);
		}
		return ( res );
	}
	
	public void clearHashValue() {
		if ( rangeValue != null ){
			rangeValue.clear();
			rangeValue = null;
		}
		return;
	}
	
	public boolean hasStands() {
		return (!stands.isEmpty() );
	}
	/**
	 * @return
	 */
	public Element getElement() {
		return element;
	}

	/**
	 * @param element
	 */
	public void setElement(Element element) {
		this.element = element;
	}
	
	public boolean hasElement() {
		boolean res=false;
		if ( element != null ){
			res = true;
		}
		return ( res );
	}

	/**
	 * @return
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param i
	 */
	public void setId() {
		id = new Integer(idSeed++);
	}

	/**
	 * @return
	 */
	public ImageElement getSideImage() {
		return sideImage;
	}

	/**
	 * @param element
	 */
	public void setSideImage(ImageElement element) {
		sideImage = element;
	}

	/**
	 * @return Returns the idSeed.
	 */
	public static int getIdSeed() {
		return idSeed;
	}

	/**
	 * @param idSeed The idSeed to set.
	 */
	public static void setIdSeed(int idSeed) {
		UnitModel.idSeed = idSeed;
	}

	/**
	 * @param id The id to set.
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param rangeValue The rangeValue to set.
	 */
	public void setRangeValue(HashMap rangeValue) {
		this.rangeValue = rangeValue;
	}

	/**
	 * @param stands The stands to set.
	 */
	public void setStands(ArrayList stands) {
		this.stands = stands;
	}

}
